<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>克隆节点</title>
</head>

<body>
  <div>
    <p>我是div内的p标签</p>
  </div>

  <script>
    //获取div元素
    var div = document.querySelector('div')

    //克隆一个div元素，不克隆后代元素
    var clone1 = div.cloneNode(false)
    //克隆一个div元素，克隆后代元素
    var clone2 = div.cloneNode(true)

    console.log('不克隆后代节点:', clone1)//空白div标签
    console.log('克隆后代节点:', clone2)//克隆的div
  </script>
</body>

</html>